from pydantic import BaseModel, ConfigDict
from datetime import datetime
from typing import Generic, List, Optional, TypeVar

T = TypeVar('T')

# 定义通用响应模型
class APIResponse(BaseModel, Generic[T]):
    success: bool = True
    data: Optional[List[T]] = None
    count: Optional[int] = None
    message: Optional[str] = None


class StockZTBase(BaseModel):
    id: Optional[int] = None
    serial_no: Optional[int] = None  # 序号
    code: Optional[str] = None  # 股票代码
    name: Optional[str] = None  # 股票名称
    change_percent: Optional[float] = None  # 涨跌幅
    latest_price: Optional[float] = None  # 最新价
    turnover: Optional[float] = None  # 成交额
    circ_market_value: Optional[float] = None  # 流通市值
    total_market_value: Optional[float] = None  # 总市值
    turnover_rate: Optional[float] = None  # 换手率
    block_fund: Optional[float] = None  # 封板资金
    first_block_time: Optional[str] = None  # 首次封板时间
    last_block_time: Optional[str] = None  # 最后封板时间
    break_block_times: Optional[int] = None  # 炸板次数
    limit_up_stat: Optional[str] = None  # 涨停统计
    continuous_limit_up: Optional[int] = None  # 连板数
    industry: Optional[str] = None  # 所属行业
    created_at: Optional[datetime] = None  # 创建时间

    # Pydantic V2 配置方式
    model_config = ConfigDict(from_attributes=True)
